<template>
  <div>
    <form>
      <label>姓名：</label>
      <input type="text" v-model="patient.name"><br><br>

      <label>年龄：</label>
      <input type="number" v-model.number="patient.age"><br><br>

      <label>身高：</label>
      <input type="number" v-model.number="patient.height">(米)<br><br>

      <label>体重：</label>
      <input type="number" v-model.number="patient.weight">(公斤)<br><br>

      <label>病史：</label>
      <input type="text" v-model="patient.medicalHistory"><br><br>

      <button v-on:click.prevent="diagnose">诊断</button>
    </form>

    <p v-if="diagnosis">患者 {{ patient.name }} 的诊断结果：{{ diagnosis }}</p>
  </div>
</template>

<script>
export default {
  data () {
    return {
      patient: {
        name: '',
        age: 0,
        height: 0,
        weight: 0,
        medicalHistory: ''
      },
      diagnosis: ''
    }
  },
  methods: {
    diagnose () {
      const bmi = this.patient.weight / (this.patient.height * this.patient.height)
      console.log(bmi)
      if (bmi < 18.5) {
        this.diagnosis = '体重过轻'
      } else if (bmi >= 18.5 && bmi < 24.9) {
        this.diagnosis = '正常'
      } else if (bmi >= 24.9 && bmi < 29.9) {
        this.diagnosis = '体重过重'
      } else {
        this.diagnosis = '肥胖'
      }
    }
  }
}
</script>
